package com.kgc.controller;


import com.kgc.dto.EvaluateDto;
import com.kgc.dto.MalfunctionDto;
import com.kgc.dto.Result;
import com.kgc.dto.UsersDto;
import com.kgc.pojo.Evaluate;
import com.kgc.service.EvaluateService;
import com.kgc.service.MalfunctionService;
import com.kgc.service.UsersService;
import com.kgc.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 评估信息 前端控制器
 * </p>
 *
 * @author zsy
 * @since 2021-08-04
 */
@RestController
@RequestMapping("/api/evaluate")
public class EvaluateController {
    @Autowired
    private MalfunctionService malfunctionService;

    @Autowired
    private UsersService usersService;

    @Autowired
    private EvaluateService evaluateService;
    /**
     * 维修信息显示功能
     * @param modelId
     * @return
     */
    @GetMapping("/specList")
    public Result<List<MalfunctionDto>> findSpecListByModelId(Long modelId){
        List<MalfunctionDto> list = malfunctionService.findSpecListByModelId(modelId);
        return ResultUtils.returnDataSuccess(list);
    }

    @PostMapping("assess")
    public Result<Evaluate> assess(Long modelId, String optionIds, HttpServletRequest request){
        //获取token
        String token = request.getHeader("token");
        //通过token获取用户信息
        UsersDto usersDto = usersService.getLoginByToken(token);

        Evaluate evaluate = evaluateService.assess(modelId,optionIds,usersDto.getId());
        return ResultUtils.returnDataSuccess(evaluate);
    }

    @GetMapping("/{id}/assessInfo")
    public Result<EvaluateDto> assessInfo(@PathVariable(name = "id")Long id){
        EvaluateDto evaluateDto = evaluateService.assessInfo(id);
        return ResultUtils.returnDataSuccess(evaluateDto);
    }


}

